package com.example.drools.spring.yc.service.impl;

import com.example.drools.spring.yc.core.YcAgendaFilter;
import com.example.drools.spring.yc.core.YcRuleEngine;
import com.example.drools.spring.yc.core.agenda.YcUniqueCheckFilter;
import com.example.drools.spring.yc.entity.YcUniqueEntity;
import com.example.drools.spring.yc.service.YcUniqueService;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author ddsyw
 * @version 1.0
 * @date 2021/12/31 3:06 下午
 */
@Slf4j
@Service
public class YcUniqueServiceImpl implements YcUniqueService {
  @Resource
  private YcRuleEngine ycRuleEngine;

  @Override
  public void checkUnique(List<? extends YcUniqueEntity> ycUniqueEntitys, String ruleName) {
    YcAgendaFilter ycAgendaFilter = new YcUniqueCheckFilter(ruleName);
    ycUniqueEntitys.forEach(ycUniqueEntity ->  ycRuleEngine.executeRuleEngine(ycAgendaFilter, ycUniqueEntity));
  }
}
